<template>
    <div class="login-container">
      <div class="login-box">
        <h2 class="login-title">系统登录</h2>
        <el-form :model="form" label-width="auto">
          <el-form-item label="用户名">
            <el-input 
              v-model="form.username" 
              class="blue-input"
              placeholder="请输入用户名"
            />
          </el-form-item>
          <el-form-item label="密码">
            <el-input 
              v-model="form.password" 
              type="password"
              class="blue-input"
              placeholder="请输入密码"
              show-password
            />
          </el-form-item>
          <el-form-item>
            <el-button 
              type="primary" 
              @click="login" 
              class="login-btn"
            >
              登录
            </el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </template>
  
  <script setup>
  import {onMounted, onUnmounted, ref} from 'vue'
  import { ElNotification } from 'element-plus'
  import axios  from 'axios';
  import { ElMessage, ElMessageBox } from 'element-plus'
  import { useRouter } from 'vue-router'
  import { useCounterStore } from "@/stores/counter.js";
  
  // 在 setup 中使用
  const router = useRouter()
  import service from '@/utils/request'
  
  let form = ref({username:'root',password:'root'})
  let counter = useCounterStore()
  function login(){
      service.post("/user/login?username="+form.value.username+"&password="+form.value.password).then(
          res=>{
             // console.log(window.__VUE_DEVTOOLS_GLOBAL_HOOK__.apps[0].config.globalProperties.$pinia)
             // console.log(import.meta.env.MODE)
              //console.log(res.data)
              if(res.data!=null){
                  //1.将userid存入pinia
                  counter.vo_user.value =res.data
  
                  //2.路由跳转
                  router.replace({path:"/"})
              }else{
                  //给提示
              }
          }
      )
  }
  </script>
  
  <style scoped>
  .login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #f5f7fa;
  }
  
  .login-box {
    width: 400px;
    padding: 30px;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  }
  
  .login-title {
    text-align: center;
    margin-bottom: 30px;
    color: #409EFF;
  }
  
  .blue-input :deep(.el-input__inner) {
    border-color: #409EFF;
    color: #409EFF;
  }
  
  .blue-input :deep(.el-input__inner:focus) {
    border-color: #66b1ff;
    box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
  }
  
  .login-btn {
    width: 100%;
    background-color: #409EFF;
    border-color: #409EFF;
  }
  
  .login-btn:hover {
    background-color: #66b1ff;
    border-color: #66b1ff;
  }
  </style>